package cn.edu.jnu.supershopper;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;

public class ShowDetailsActivity extends AppCompatActivity {
    private ArrayList<Book> BookList = new ArrayList<>();
    private MyImageView myImageView;
    private TextView name;
    private TextView author;
    private TextView published;
    private TextView doubanScore;
    private TextView ISBN;
    private TextView description;
    private TextView author_info;
    private TextView publishing;
    private Book book;
    private int position;
    private BookDataSaver dataSaver;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_details);

        // 得到启动这个activity的intent
        Intent intent = getIntent();
        position = intent.getIntExtra("position", 0);
        dataSaver = new BookDataSaver();
        BookList = dataSaver.Load(this);
        book = BookList.get(position);

        myImageView = (MyImageView) findViewById(R.id.book_cover_details);
        author_info = findViewById(R.id.author_info);
        publishing = findViewById(R.id.Publishing);
        name = findViewById(R.id.name);
        author = findViewById(R.id.author);
        published = findViewById(R.id.Published);
        doubanScore = findViewById(R.id.doubanScore);
        ISBN = findViewById(R.id.ISBN);
        description = findViewById(R.id.description);
        String URL = book.getPhotoUrl();
        String imagePath = book.getimagePath();
        if (imagePath != null) {
            Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
            myImageView.setImageBitmap(bitmap);
        } else {
            if (!URL.equals("暂无信息")) myImageView.setImageURL(URL);
            else myImageView.setImageResource(book.getImageId());
        }
        author_info.setText(book.getAuthorlntro());
        publishing.setText(book.getPublishing());
        ISBN.setText(book.getIsbn());
        name.setText(book.getName());
        author.setText(book.getAuthor());
        published.setText(book.getIsbn());
        doubanScore.setText(book.getDoubanScore());
        description.setText(book.getDescription());
    }


}